package com.srb.core.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.srb.common.result.R;
import com.srb.core.pojo.entity.Borrower;
import com.srb.core.pojo.vo.BorrowerDetailVo;
import com.srb.core.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author dapeng
 * @since 2021-08-08
 */
@Api(tags = {"借款人管理"})
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {

    @Autowired
    private BorrowerService borrowerService;

    @ApiOperation(value = "获取借款人分页列表")
    @GetMapping(value = {"/list/{page}/{limit}"})
    public R listPage(
            @ApiParam(value = "当前页码",required = true)
            @PathVariable(value = "page")Long page,

            @ApiParam(value = "每页记录数",required = true)
            @PathVariable(value = "limit")Long limit,

            @ApiParam(value = "查询关键字",required = false)
            @RequestParam String keyword){
        Page<Borrower> pageParam = new Page<Borrower>(page, limit);
        IPage<Borrower> pageModel = borrowerService.listPage(pageParam,keyword);
        return R.ok().data("pageModel",pageModel);
    }

    @ApiOperation(value = "获取借款人信息")
    @GetMapping(value = {"/show/{id}"})
    public R show(@ApiParam(value = "借款人id",required = true) @PathVariable(value = "id") Long id){
        BorrowerDetailVo vo = borrowerService.getBorrowerDetailById(id);
        return R.ok().data("borrowerDetailVo",vo);
    }
}

